package com.snsoft.service.environment;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.snsoft.bean.GreenHouseInfo;
import com.snsoft.dao.EnvironmentDao;
import com.snsoft.exception.BaseNotFound;
import com.snsoft.exception.GreenHouseNotFound;

/**
 * 
 * @copyright ：神农大学生软件创新中心 版权所有 © 2017
 * 
 * @author 16计算机弓耀
 * 
 * @version 1.0
 * 
 * @date 2017年11月8日下午4:46:26
 * 
 * @Description TODO
 *	获取温室列表接口
 */
public class GetGreenHouseListService {
	//普通用户获取温室列表
	public List<GreenHouseInfo> getGreenHouseListByCommon(String userID) throws SQLException, GreenHouseNotFound, BaseNotFound{
		EnvironmentDao ed = new EnvironmentDao();
		List<Map<String, Object>> list = ed.getCompanyIDList(userID);
		List<GreenHouseInfo> result = new ArrayList<GreenHouseInfo>();
		if (list.isEmpty()) {
			throw new BaseNotFound("基地不存在");
		}
		for (Map<String, Object> map : list) {
			if (ed.getGreenHouseList(Integer.parseInt(map.get("companyID").toString())) != null) {
				result.addAll(ed.getGreenHouseList(Integer.parseInt(map.get("companyID").toString())));
			}
		}
		return result;
	}
	
	public List<GreenHouseInfo> getGreenHouseList(int companyID) throws SQLException, GreenHouseNotFound{
		EnvironmentDao ed = new EnvironmentDao();
		List<GreenHouseInfo> result = ed.getGreenHouseList(companyID);
		if(result.isEmpty()) {
			throw new GreenHouseNotFound("温室不存在");
		}
		return result;
	}
}
